package com.ai.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ai.entity.SysContentEntity;
import com.ai.service.SysContentService;
import com.ai.web.PageResp;
import com.ai.web.request.ContentAddReq;
import com.ai.web.request.ContentPageReq;
import com.ai.web.request.ContentUpdateReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 文章管理
 */
@Api(tags = "文章管理")
@RestController
@RequestMapping("/sysContent")
public class SysContentController {

    @Resource
    private SysContentService sysContentService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @SaCheckPermission("sysContent:add")
    public void add(@RequestBody ContentAddReq contentAddReq) {
        sysContentService.save(contentAddReq);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    @SaCheckPermission("sysContent:delete")
    public void delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
        sysContentService.deleteByIds(ids);
    }

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    @SaCheckPermission("sysContent:update")
    public void update(@RequestBody ContentUpdateReq contentUpdateReq) {
        sysContentService.updateById(contentUpdateReq);
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("/listByPage")
    @SaCheckPermission("sysContent:list")
    public PageResp<SysContentEntity> findListByPage(@RequestBody ContentPageReq contentPageReq) {
        return sysContentService.page(contentPageReq);
    }

}
